function po_fa_show_fuel () {
    var fuel = localStorage.getItem ("fa_fuel");
    var cargo = localStorage.getItem ("fa_fuel_cargo");
    var tankSize = localStorage.getItem ("po_fa_tank_size");
    if (!fuel) return;
    
    var inputs = document.getElementsByTagName ("input");
    for (var i=0; i<inputs.length; i++) {
        var anInput = inputs[i];
        if (anInput.type == "submit" && anInput.value == "<- Transfer ->") {
            var td = anInput.parentNode.parentNode.previousSibling.getElementsByTagName("td")[0];
            var div = document.createElement ("span");
            var fuelN = Number(fuel);
            var cargoN = Number (cargo);
	    var link = null;
            if ((fuelN+cargoN) < (tankSize/3)) {
                div.setAttribute ("style", "color:red;font-weight:bold;");
            }
	    if ((fuelN+cargoN) < (tankSize-0.25)) {
		link = document.createElement ("a");
		link.textContent = ", buy "+Math.ceil(tankSize-fuelN-cargoN);
		link.setAttribute ("href", "javascript:po_fa_buy_fuel('"+Math.ceil(tankSize-fuelN-cargoN)+"')");
	    }
            div.innerHTML = " (Fuel: "+fuel+"+"+cargo;
	    if (link) {
		div.appendChild(link);
	    }
	    div.innerHTML += ")";
            //td.insertBefore (div, td.firstChild);
            td.appendChild (div);
            break;
        }
    }
}

function po_fa_buy_fuel (amount) {
    var input = document.getElementById ('buy_16');
    if (!input) return;
    input.value = amount;
}

po_fa_show_fuel ();